Skip to content

Fix Issue 886: VB -> C# wrong conversion of optional struct or decimal ref parameter#1238

Draft
GrahamTheCoder wants to merge 1 commit intomasterfrom
jules-fix-issue-886-15338263271799288852
Draft

Fix Issue 886: VB -> C# wrong conversion of optional struct or decimal ref parameter#1238
GrahamTheCoder wants to merge 1 commit intomasterfrom
jules-fix-issue-886-15338263271799288852

Conversation

@GrahamTheCoder
Copy link
Copy Markdown
Member

This PR fixes an issue where converting Optional ByRef VB.NET parameters initialized with Nothing for custom structures or numeric Decimal defaults emitted C# code that fails to compile due to C# compiler limitations with [DefaultParameterValue].

Changes:

  1. ExpressionNodeVisitor.cs: For [DefaultParameterValue], decimal parameter primitive defaults now properly emit an equivalent constant int or double valid attribute expression, without the decimal m suffix which is disallowed. For generic structs (TypeKind.Struct and SpecialType.None), no DefaultParameterValue attribute will be generated as custom structs with non-null defaults fail natively on C#.
  2. ArgumentConverter.cs: Whenever default parameters expand for variable definitions around callers (ref arguments), non-nullable structs initialized to null instead will yield their expected default initialization.
  3. Added the expected unit test OptionalByRefParameterAsync886 and verified it passes correctly alongside all project suites.

PR created automatically by Jules for task 15338263271799288852 started by @GrahamTheCoder

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@GrahamTheCoder GrahamTheCoder marked this pull request as ready for review April 12, 2026 23:37
var literalValue = literalExpr.Token.Value;
if (literalValue is decimal decimalVal) {
var isInteger = decimalVal == Math.Round(decimalVal);
var newLiteral = isInteger ? CommonConversions.Literal((int)decimalVal) : CommonConversions.Literal((double)decimalVal);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit risky to cast decimal to double if someone really did need the last half of the precision. We should add a condition to check if the number round trips and error otherwise

@GrahamTheCoder GrahamTheCoder marked this pull request as draft April 12, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant